package ro.gateway.aida.obj;

import java.sql.Date;
import java.util.Comparator;
import java.util.List;


/**
 * <p>Title: Local Projects Database</p>
 * <p>Description: AiDA</p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: eRomania Gateway</p>
 * @author Mihai Postelnicu
 * @version 1.0-* @version $Id: Person.java,v 1.2 2005/03/07 17:31:24 mihaipostelnicu Exp $
 */

public class Person {
    private String firstNames = "";
    private String lastName = "";
    private String department = "";
    private String state = "";
    private String address = "";
    private String postalCode = "";
    private String phone = "";
    private String fax = "";
    private String email = "";
    private String countryISO3 = "";
    private String URL = "";
    private long id = -1;
    private long userID = -1;
    private boolean selected;
    private String countryName;
    private Date update;
    private List assignedToOrgs;

    public Person() {
		selected=false;
    }

    public String getName() {
        return getFirstNames() + " " + getLastName();
    }

    public String getFirstNames() {
        return firstNames;
    }

    public void setFirstNames(String firstNames) {
        this.firstNames = firstNames;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getAddress() {
        return (address == null) ? "" : address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPostalCode() {
        return (postalCode == null) ? "" : postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getRawPhone() {
    	return phone;
    }
    
    public String getRawFax() {
    	return fax;
    }
    
    public String getPhone() {
    	if(phone==null) return null;
        return phone.replace('#','-');
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    public String getPhone(int id) {
    	if(phone==null) return null;
        if(phone.indexOf('#')==-1)
        	{
        		if(id!=3) return "";
        		return phone;
        	}
        String parts[]=phone.split("#");
        if(parts.length==0) return null;
        return parts[id-1];
    }

    public String getFax(int id) {
    	if(fax==null) return null;
        if(fax.indexOf('#')==-1)
        	{
        		if(id!=3) return "";
        		return fax;
        	}
        String parts[]=fax.split("#");
        if(parts.length==0) return null;
        return parts[id-1];
    }
    
    
    public String getFax() {
    	if(fax==null) return null;
        return fax.replace('#','-');
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCountryISO3() {
        return countryISO3;
    }

    public void setCountryISO3(String countryISO3) {
        this.countryISO3 = countryISO3;
    }

    public String getURL() {
        return URL;
    }

    public void setURL(String URL) {
        this.URL = URL;
    }

    public long getId() {
        return id;
    }

    public void setId(long ID) {
        this.id = ID;
    }

    public long getUserID() {
        return userID;
    }

    public void setUserID(long userID) {
        this.userID = userID;
    }

    /**
     * @return
     */
    public String getCountryName() {
        return countryName;
    }

    /**
     * @param string
     */
    public void setCountryName(String string) {
        countryName = string;
    }

    /**
     * @return
     */
    public Date getUpdate() {
        return update;
    }

    /**
     * @param date
     */
    public void setUpdate(Date date) {
        update = date;
    }

    public String getFullName() {
        return firstNames + "," + lastName;
    }

    public static class DateComparator implements Comparator {
        public DateComparator() {
        }

        public int compare(Object o1, Object o2) {
            Person p1 = (Person) o1;
            Person p2 = (Person) o2;

            return (p1.getUpdate().compareTo(p2.getUpdate()));
        }
    }

    public static class NameComparator implements Comparator {

        public NameComparator() {
          
        }

        public int compare(Object o1, Object o2) {
			Person p1 = (Person) o1;
			 Person p2 = (Person) o2;

            return (p1.getName().compareTo(p2.getName()));
        }
    }
	/**
	 * @return
	 */
	public boolean isSelected() {
		return selected;
	}

	/**
	 * @param b
	 */
	public void setSelected(boolean b) {
		selected = b;
	}
	public static final String SELECTED="SelectedPerson";
    /**
     * @return Returns the assignedToOrgs.
     */
    public List getAssignedToOrgs() {
        return assignedToOrgs;
    }
    /**
     * @param assignedToOrgs The assignedToOrgs to set.
     */
    public void setAssignedToOrgs(List assignedToOrgs) {
        this.assignedToOrgs = assignedToOrgs;
    }
}
